 using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace MiniProjectWS
{
    
    public class GAALeagueData : IGAALeagueData
    {
        public List<string> QueryAllTeamsInAllDivisions()//find all teams and their corresponding division
        {
            
            EADMiniProjectEntities EAD = new EADMiniProjectEntities();          
            var queryAllTeams = EAD.CountyDivisions.OrderBy(c=>c.County);      
            List<string> teams = new List<string>();                           
            foreach (var item in queryAllTeams)
            {
               teams.Add(item.County + " " + item.League_Division);         
            }

            return teams;           
            
          
        }
        public List<string> QueryTeamDivision(string teamName)                      //query: specify a county and get their division back
        {
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryTeamDivision = Ead.CountyDivisions.Where(t => t.County == teamName);
            List<string> res = new List<string>();
            foreach (var result in queryTeamDivision)
            {
                res.Add(result.County + " " + result.League_Division);
            }
            return res;
        }
        public List<string> QueryAllTeamsInADivision(string division)           //specify a division and get all the teams in it
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var allTeamsInDivision = Ead.CountyDivisions.Where(t => t.League_Division == division);
            foreach (var r in allTeamsInDivision)
            {
                result.Add(r.County);
            }
            return result;

        }
        public List<string> QueryFixturesByDivision(string division)            //specify a division and get all the fixutures in that division
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryDivisionFixtures = Ead.FixtureDatas.Where(t => t.Division == division);
            foreach (var r in queryDivisionFixtures)
            {
                result.Add(r.Home_Team + " v " + r.Away_Team + " on " + r.Fixture_Date);
            }

            return result;

        }
        public List<string> QueryFixturesByTeam(string teamName)                                //find all the home and away fixtures for a specified team
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryDivisionFixtures = Ead.FixtureDatas.Where(t => t.Home_Team == teamName);
            var queryDivFix = Ead.FixtureDatas.Where(xt => xt.Away_Team == teamName);
            foreach (var r in queryDivisionFixtures)
            {
                result.Add(r.Home_Team + " v " + r.Away_Team + " on " + r.Fixture_Date);
            }
            foreach (var rs in queryDivFix)
            {
                result.Add(rs.Home_Team + " v " + rs.Away_Team + " on " + rs.Fixture_Date);
            }
            return result;

        }
        public List<string> QueryAllFixtures()                                  //get all fixtures for all teams
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryTeamDivision = Ead.FixtureDatas.OrderBy(t=>t.Division);            
            foreach (var rs in queryTeamDivision)
            {
                result.Add(rs.Home_Team + " v " + rs.Away_Team + " on " + rs.Fixture_Date);
            }
            return result;

        }
        public List<string> QueryFixturesByHomeTeam(string teamName)                        //get the home fixtures for a specified team
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryDivisionFixtures = Ead.FixtureDatas.Where(t => t.Home_Team == teamName).OrderBy(t => t.Home_Team);
            foreach (var r in queryDivisionFixtures)
            {
                result.Add(r.Home_Team + " v " + r.Away_Team + " on " + r.Fixture_Date);
            }
           return result;

        }
        public List<string> QueryFixturesByAwayTeam(string teamName)                    //get the away fixtures for a specified team
        {
            List<string> result = new List<string>();
            EADMiniProjectEntities Ead = new EADMiniProjectEntities();
            var queryDivisionFixtures = Ead.FixtureDatas.Where(t => t.Away_Team == teamName).OrderBy(t=>t.Away_Team);
            foreach (var r in queryDivisionFixtures)
            {
                result.Add(r.Home_Team + " v " + r.Away_Team + " on " + r.Fixture_Date);
            }
            return result;
        }
        
        
    }
}
